Malaysia Covid19 Case Updates

Prepared By: Zahiruddin Zahidanishah

In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
import dataframe_image as dfi
import adjustText as aT
from jupyterthemes import jtplot
#import requests
import cufflinks as cf
#from bs4 import BeautifulSoup as bs
jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False) 
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 
init_notebook_mode(connected=True)
cf.go_offline()

from IPython.display import display_html
def display_side_by_side(*args):
    html_str=''
    for df in args:
        html_str+=df.to_html()
    display_html(html_str.replace('table','table style="display:inline"'),raw=True)
In [2]:
#Covid19 Malaysia States Dataset from MOH, Malaysia Github accounts 
df_states_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_state.csv')
df_states_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_state.csv')
df_states_hosp = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/hospital.csv')
df_states_icu = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/icu.csv')
df_states_pkrc = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/pkrc.csv')
df_states_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_state.csv')
df_states_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_state.csv')
df_states_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
In [3]:
df_hosp_daily = df_states_hosp.groupby('date').sum().reset_index()
df_hosp_daily['admitted_covid_cum'] = df_hosp_daily['admitted_covid'].cumsum()
df_hosp_daily['discharged_covid_cum'] = df_hosp_daily['discharged_covid'].cumsum()
df_icu_daily = df_states_icu.groupby('date').sum().reset_index()
df_icu_daily['icu_covid_cum'] = df_icu_daily['icu_covid'].cumsum()
df_pkrc_daily = df_states_pkrc.groupby('date').sum().reset_index()
df_pkrc_daily['admitted_covid_cum'] = df_pkrc_daily['admitted_covid'].cumsum()
df_pkrc_daily['discharged_covid_cum'] = df_pkrc_daily['discharged_covid'].cumsum()
In [4]:
#Selecting the required columns
df_states_cases = df_states_cases[['date','state','cases_new','cases_recovered','cases_pvax','cases_fvax']]
df_date_start = df_states_cases.head(1)
df_date_end = df_states_cases.tail(1)
df_states_deaths = df_states_deaths[['date','state','deaths_new_dod','deaths_bid_dod','deaths_pvax','deaths_fvax']]
df_states_hosp = df_states_hosp[['date','state','admitted_covid','discharged_covid']]
df_states_vaksin = df_states_vaksin[['date','state','daily_partial','daily_full','daily_booster','daily']]
df_states_pop = df_states_pop[['state','pop']]
In [5]:
#Grouping and summation the detasets based on states columns
df_cases = df_states_cases.groupby('state').sum()
df_deaths = df_states_deaths.groupby('state').sum()
df_hosp = df_states_hosp.groupby('state').sum()
df_vaksin = df_states_vaksin.groupby('state').sum()
In [6]:
#Merging the datasets into one datasets
df_states = pd.merge(df_cases,df_deaths,on='state')
In [7]:
df_states = pd.merge(df_states,df_hosp,on='state')
In [8]:
df_states = pd.merge(df_states,df_vaksin,on='state')
In [9]:
df_states = pd.merge(df_states,df_states_pop,on='state')
In [10]:
#Creating main tables for presentation
df_states_table = df_states
df_states_table['deaths_vax_total'] = df_states_table['deaths_pvax'] + df_states_table['deaths_fvax']
df_states_table['cases_vax_total'] = df_states_table['cases_pvax'] + df_states_table['cases_fvax']

df_states_table = df_states_table[['state','cases_new','cases_recovered','cases_vax_total','deaths_new_dod',
                                  'deaths_bid_dod','deaths_vax_total','daily_partial','daily_full','daily',
                                   'daily_booster','pop']]

df_states_table.loc['Total'] = df_states_table.sum(numeric_only=True, axis=0)
df_states_table['state'] = df_states_table['state'].replace(np.nan, 'Malaysia')

df_states_table['Cases (%)'] = df_states_table['cases_new']/df_states_table['pop']*100
df_states_table['Cases Recovered (%)'] = df_states_table['cases_recovered']/df_states_table['cases_new']*100
df_states_table['Cases Vax. (%)'] = df_states_table['cases_vax_total']/df_states_table['cases_new']*100
df_states_table['Deaths (%)'] = df_states_table['deaths_new_dod']/df_states_table['cases_new']*100
df_states_table['Deaths Vax. (%)'] = df_states_table['deaths_vax_total']/df_states_table['deaths_new_dod']*100
df_states_table['Deaths BID (%)'] = df_states_table['deaths_bid_dod']/df_states_table['deaths_new_dod']*100
df_states_table['Vax. 3D (%)'] = df_states_table['daily_booster']/df_states_table['pop']*100
df_states_table['Vax. 2D (%)'] = df_states_table['daily_full']/df_states_table['pop']*100
df_states_table['Vax. 1D (%)'] = df_states_table['daily_partial']/df_states_table['pop']*100

df_states_table.rename(columns={'state':'States','cases_new':'Cases Positive','cases_recovered':'Cases Recovered',
                               'cases_vax_total':'Cases Vax.','deaths_new_dod':'Death Cases',
                               'deaths_bid_dod':'Death BID','deaths_vax_total':'Deaths Vax.',
                               },inplace=True)#'daily':'Total Vaccinated','pop':'Population'
In [11]:
#Creating the main key points from the datasets
print('Key Points Highlights:-')
print('-----------------------------------------------------------------')
print('Report Start Date                        :', df_date_start.at[df_date_start.index[0],'date'])
print('Report End Date                          :', df_date_end.at[df_date_end.index[0],'date'])
print('1. Total Positive Cases                  :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Positive']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases (%)']),'%')
print('2. Total Positive Cases After Vaccinated :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax. (%)']),'%')
print('3. Total Recovered Cases                 :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered (%)']),'%')
print('4. Total Death Cases                     :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Death Cases']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths (%)']),'%')
print('5. Total Death Cases After Vaccinated    :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax. (%)']),'%')
print('6. Total 1 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_partial']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 1D (%)']),'%')
print('7. Total 2 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_full']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 2D (%)']),'%')
print('8. Total 3 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_booster']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 3D (%)']),'%')
print('-----------------------------------------------------------------')
Key Points Highlights:-
-----------------------------------------------------------------
Report Start Date                        : 2020-01-25
Report End Date                          : 2022-01-27
1. Total Positive Cases                  : 2,850,408 / 8.7 %
2. Total Positive Cases After Vaccinated : 1,117,189 / 39.2 %
3. Total Recovered Cases                 : 2,770,663 / 97.2 %
4. Total Death Cases                     : 31,940 / 1.1 %
5. Total Death Cases After Vaccinated    : 11,007 / 34.5 %
6. Total 1 Dose Vaccinated               : 25,861,466 / 79.2 %
7. Total 2 Dose Vaccinated               : 25,707,708 / 78.7 %
8. Total 3 Dose Vaccinated               : 11,531,403 / 35.3 %
-----------------------------------------------------------------
In [12]:
df_states_table.drop(['daily_partial','daily_full','pop','daily','daily_booster'],axis='columns',inplace=True)
In [13]:
df_states_table.drop(['Cases Vax.','Death BID','Deaths Vax.'],axis='columns',inplace=True)

df_states_table.style.set_caption("Malaysia Details Of Covid19 Cases At Each States").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}','Death Cases':'{:,.0f}',
     'Deaths (%)':'{:,.1f}','Deaths BID':'{:,.0f}','Deaths Vax.':'{:,.0f}','Cases (%)':'{:,.1f}',
     'Cases Recovered (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Vax. 2D (%)':'{:,.1f}','Vax. 1D (%)':'{:,.1f}',
     'Deaths Vax. (%)':'{:,.1f}','Deaths BID (%)':'{:,.1f}','Vax. 3D (%)':'{:,.1f}'}
).set_properties(subset=['States'],**{'text-align': 'left'}).apply(
    lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[13]:
Malaysia Details Of Covid19 Cases At Each States
States Cases Positive Cases Recovered Death Cases Cases (%) Cases Recovered (%) Cases Vax. (%) Deaths (%) Deaths Vax. (%) Deaths BID (%) Vax. 3D (%) Vax. 2D (%) Vax. 1D (%)
Johor 256,533 243,543 3,909 6.8 94.9 36.5 1.5 37.2 12.7 33.5 80.7 81.4
Kedah 175,624 170,934 2,186 8.0 97.3 38.3 1.2 32.5 14.8 26.0 72.2 72.6
Kelantan 177,091 172,962 1,274 9.3 97.7 43.3 0.7 34.4 22.6 12.7 61.9 62.6
Melaka 80,531 78,233 970 8.6 97.1 36.5 1.2 37.0 13.2 45.6 76.9 77.4
Negeri Sembilan 118,355 114,341 1,334 10.5 96.6 28.4 1.1 28.7 10.9 41.2 84.2 84.8
Pahang 100,889 97,740 801 6.0 96.9 42.4 0.8 34.1 12.5 27.7 70.2 70.5
Perak 132,615 129,786 1,430 5.3 97.9 39.3 1.1 43.2 13.1 28.9 74.2 74.6
Perlis 7,533 7,240 138 3.0 96.1 57.3 1.8 44.9 5.1 19.7 80.3 80.8
Pulau Pinang 166,607 163,040 1,768 9.4 97.9 43.1 1.1 40.0 21.2 42.7 86.1 86.6
Sabah 246,754 238,404 2,827 6.3 96.6 36.3 1.1 23.7 39.1 11.4 61.3 59.5
Sarawak 252,751 251,037 1,622 9.0 99.3 54.3 0.6 49.0 20.8 50.8 75.8 77.4
Selangor 810,296 787,899 10,054 12.4 97.2 36.3 1.2 32.6 21.1 44.3 73.2 74.0
Terengganu 84,973 83,450 754 6.7 98.2 45.6 0.9 41.2 11.0 21.8 70.0 70.6
W.P. Kuala Lumpur 218,702 211,572 2,700 12.3 96.7 36.1 1.2 34.4 25.6 79.9 170.9 172.4
W.P. Labuan 11,052 10,861 151 11.1 98.3 19.0 1.4 9.3 28.5 37.3 80.2 83.2
W.P. Putrajaya 10,102 9,621 22 9.2 95.2 45.3 0.2 31.8 4.5 57.6 134.0 136.6
Malaysia 2,850,408 2,770,663 31,940 8.7 97.2 39.2 1.1 34.5 20.2 35.3 78.7 79.2
In [14]:
df_states_graph = df_states
df_states_graph['vaksin_percentage_partial'] = df_states_graph['daily_partial']/df_states_graph['pop']*100
df_states_graph['vaksin_percentage_full'] = df_states_graph['daily_full']/df_states_graph['pop']*100
df_states_graph['deaths_vax_total'] = df_states_graph['deaths_pvax'] + df_states_graph['deaths_fvax']
df_states_graph['cases_vax_total'] = df_states_graph['cases_pvax'] + df_states_graph['cases_fvax']
In [15]:
#Dataset for overall Malaysia Covid19
df_mas_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv')
df_mas_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv')
df_mas_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_malaysia.csv')
df_mas_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv')
df_mas_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
df_mas_aefi = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/vaccination/aefi.csv')
In [16]:
df_mas_vaksin['Total Pfizer'] = df_mas_vaksin['pfizer1'] + df_mas_vaksin['pfizer2']
df_mas_vaksin['Total Sinovac'] = df_mas_vaksin['sinovac1'] + df_mas_vaksin['sinovac2']
df_mas_vaksin['Total AstraZ'] = df_mas_vaksin['astra1'] + df_mas_vaksin['astra2']
df_mas_vaksin['Cum. Daily'] = df_mas_vaksin['daily_full'].cumsum()
df_mas_vaksin['Population'] = df_states_pop.at[df_states_pop.index[0],'pop']
df_mas_vaksin['Vax. (%)'] = (df_mas_vaksin['Cum. Daily']/df_mas_vaksin['Population'])*100
In [17]:
df_mas_cases = df_mas_cases[['date','cases_new','cases_recovered','cases_pvax','cases_fvax']]
df_mas_deaths = df_mas_deaths[['date','deaths_new_dod','deaths_bid_dod','deaths_pvax','deaths_fvax']]
df_mas_vaksin = df_mas_vaksin[['date', 'daily_partial', 'daily_full', 'daily_booster', 'daily', 'Total Pfizer',
                               'Total Sinovac', 'Total AstraZ', 'cansino', 'Cum. Daily', 'Vax. (%)']]
In [18]:
df_mas = pd.merge(df_mas_cases, df_mas_deaths, on='date')
In [19]:
df_mas = pd.merge(df_mas, df_mas_vaksin, on='date')
In [20]:
df_mas_deaths['deaths_vax_total'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax']
df_mas['deaths_vax_total'] = df_mas['deaths_pvax'] + df_mas['deaths_fvax']
df_mas_test['total_test'] = df_mas_test['rtk-ag'] + df_mas_test['pcr']
df_mas_test['cum_total'] = df_mas_test['total_test'].cumsum()
In [21]:
df_mas_new = df_mas[['date','cases_new','deaths_new_dod']]
df_mas_new['cases_new_7'] = df_mas_new['cases_new'].shift(7)
df_mas_new['cases_new_14'] = df_mas_new['cases_new'].shift(14)
df_mas_new['cases_new_21'] = df_mas_new['cases_new'].shift(21)
df_mas_new['deaths_new_7'] = df_mas_new['deaths_new_dod'].shift(7)
df_mas_new['deaths_new_14'] = df_mas_new['deaths_new_dod'].shift(14)
df_mas_new['deaths_new_21'] = df_mas_new['deaths_new_dod'].shift(21)
df_mas_new = df_mas_new.tail(7)
df_mas_new['cum_new'] = df_mas_new['cases_new'].cumsum()
df_mas_new['cum_new_7'] = df_mas_new['cases_new_7'].cumsum()
df_mas_new['cum_new_14'] = df_mas_new['cases_new_14'].cumsum()
df_mas_new['cum_new_21'] = df_mas_new['cases_new_21'].cumsum()
df_mas_new['cum_deaths_new'] = df_mas_new['deaths_new_dod'].cumsum()
df_mas_new['cum_deaths_7'] = df_mas_new['deaths_new_7'].cumsum()
df_mas_new['cum_deaths_14'] = df_mas_new['deaths_new_14'].cumsum()
df_mas_new['cum_deaths_21'] = df_mas_new['deaths_new_21'].cumsum()
In [22]:
print('Four Weeks Cumulative Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1: ', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()-df_mas_new['cum_new_7'].mean()),'diff.)')
print('Average Week 2: ', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()-df_mas_new['cum_new_14'].mean()),'diff.)')
print('Average Week 3: ', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()-df_mas_new['cum_new_21'].mean()),'diff.)')
print('Average Week 4: ', '{0:,.0f}'.format(df_mas_new['cum_new_21'].mean()), '-')
print('--------------------------------------------')
print('Four Weeks Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1:', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()-df_mas_new['cases_new_7'].mean()),'diff.)')
print('Average Week 2:', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()-df_mas_new['cases_new_14'].mean()),'diff.)')
print('Average Week 3:', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()-df_mas_new['cases_new_21'].mean()),'diff.)')
print('Average Week 4:', '{0:,.0f}'.format(df_mas_new['cases_new_21'].mean()), '-')
print('--------------------------------------------')
Four Weeks Cumulative Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1:  16,040 ( 3,720 diff.)
Average Week 2:  12,320 ( -220 diff.)
Average Week 3:  12,540 ( -189 diff.)
Average Week 4:  12,729 -
--------------------------------------------
Four Weeks Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1: 4,212 ( 1,067 diff.)
Average Week 2: 3,144 ( -30 diff.)
Average Week 3: 3,174 ( 5 diff.)
Average Week 4: 3,169 -
--------------------------------------------
In [23]:
fig = make_subplots(rows=1, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>New Confirmed Cases Daily</b>',
                                   '<b>New Confirmed Cases Cumulative</b>',
                                   '<b>New Deaths Cases Daily</b>',
                                   '<b>New Deaths Cases Cumulative</b>'))
#Graph 1
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=1)
#Graph 2
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="top left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=2)
#Graph 3
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_dod'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_dod'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=3)
#Graph 4
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_new'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="top right",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,title_text="Malaysia Covid19 Latest Cases In Details (4 Week Comparison)", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black',
                visible=True, showticklabels=False)
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [24]:
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new_dod'].cumsum()
df_mas_deaths['cum_deaths_vax'] = df_mas_deaths['deaths_vax_total'].cumsum()
In [25]:
fig = make_subplots(rows=2, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                    specs=[[{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}], 
                           [{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],

subplot_titles=('<b>Cases: Total VS Recover</b>',
                '<b>ICU Daily Admitted</b>',
                '<b>Hosp.: Admit VS Discharge</b>',
                '<b>PKRC: Admitted VS Discharged</b>',
                '<b>Deaths: Total, BID & Vax.</b>',
                '<b>Total Daily Covid19 Test</b>',
                '<b>States Hosp. Admission & Discharge</b>',
                '<b>States Vax. (%): 1D VS 2D</b>'))

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name='Positive Cases',
                           line = dict(color='red',width=0.5)), row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name='Positive Cases',
                           line = dict(color='red',width=1)), row=1, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=0.5)),row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=1)),row=1, col=1, secondary_y=False)
fig.add_hline(y=df_mas_cases['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cases", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_cases['cases_recovered'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Recovered", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid'],name='ICU Covid',
                           line = dict(color='blue', width=0.5)),row=1, col=2, secondary_y=True)
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid_cum'],name='ICU Covid',
                           line = dict(color='red', width=0.5)),row=1, col=2, secondary_y=False)
fig.add_hline(y = df_icu_daily['icu_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y = df_icu_daily['icu_covid_cum'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cum.", annotation_position="bottom left",row=1, col=2)
# Graph 3
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_new_dod'],name='Deaths Cases',
                           line = dict(width=0.5, color='blue')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths'],name='Deaths Cases',
                           line = dict(width=1, color='blue')),row=2, col=1, secondary_y=False)
fig.add_hline(y=df_mas_deaths['deaths_new_dod'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Deaths", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_bid_dod'],name='BID Cases',
                           line = dict(width=0.5, color='red')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_vax_total'],name='Deaths Vaccinated Cases',
                            line = dict(width=0.5, color='black')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths_vax'],name='Deaths Vaccinated Cases',
                            line = dict(width=1, color='black')),row=2, col=1, secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['total_test'],name='Daily Covid19 Test',
                           line = dict(color='blue', width=0.5)),row=2, col=2, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['cum_total'],name='Cumulative Covid19 Test',
                           line = dict(color='red', width=1)),row=2, col=2, secondary_y=True)
fig.add_hline(y=df_mas_test['total_test'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Test", annotation_position="top left",row=2, col=2)
#Graph 5
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=3, secondary_y=False)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=3, secondary_y=False)
fig.add_hline(y = df_hosp_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y = df_hosp_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=3)
#Graph 6
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=4, secondary_y=False)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=4, secondary_y=False)
fig.add_hline(y = df_pkrc_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y = df_pkrc_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=4)
#Graph 7
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['admitted_covid'],name='Admitted Cases',
                       marker_color='blue'),row=2, col=3, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['discharged_covid'],name='Discharged Cases',
                       marker_color='red'),row=2, col=3, secondary_y=False)
#Graph 8
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_partial'],
                        name='Partial Vaksin (%)',marker_color='blue'),row=2, col=4, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_full'],
                        name='Full Vaksin (%)',marker_color='red'),row=2, col=4, secondary_y=False)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=600,showlegend=False,title_text="Malaysia Covid19 Cases Overview", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

# add a horizontal line & annotations
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0=0, x1=16, xref="paper", y0=90, y1=90, yref="y",row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x=6, y=90, arrowhead=1, showarrow=True,row=2, col=4)
#Plotting the graph
fig.show()
In [26]:
df_mas_monthly = df_mas_cases.append(df_mas_deaths)

def getYearMonth(s):
  return s.split("-")[1]+"-"+s.split("-")[0]
df_mas_monthly['YearMonth']= df_mas_monthly['date'].apply(lambda x: getYearMonth(x))

df_mas_monthly = df_mas_monthly.groupby('YearMonth').sum()
df_mas_monthly = df_mas_monthly.reset_index()
df_mas_monthly['vax_total_cases'] = df_mas_monthly['cases_fvax']+df_mas_monthly['cases_pvax']
df_mas_monthly['vax_total_deaths'] = df_mas_monthly['deaths_fvax']+df_mas_monthly['deaths_pvax']
In [27]:
df_mas_yearly = df_mas_cases.append(df_mas_deaths)

def getYear(s):
  return s.split("-")[0]

def getMonth(s):
  return s.split("-")[1]

df_mas_yearly['Year']= df_mas_yearly['date'].apply(lambda x: getYear(x))
df_mas_yearly['Month']= df_mas_yearly['date'].apply(lambda x: getMonth(x))

df_mas_yearly = df_mas_yearly.groupby('Year').sum().reset_index()
df_mas_yearly['vax_total_cases'] = df_mas_yearly['cases_fvax']+df_mas_yearly['cases_pvax']
df_mas_yearly['vax_total_deaths'] = df_mas_yearly['deaths_fvax']+df_mas_yearly['deaths_pvax']
In [28]:
fig = make_subplots(rows=1, cols=2, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>Yearly Total Covid19 Cases & Recovered</b>',
                                   '<b>Monthly Total Covid19 Cases & Recovered</b>'))
#Graph 1
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_new'],
                        name='Cases Positive',marker_color='indianred'),row=1, col=1)
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_recovered'],
                        name='Cases Recovered',marker_color='lightsalmon'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_new'],
                        name='Cases Positive',marker_color='indianred'),row=1, col=2)
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_recovered'],
                        name='Cases Recovered',marker_color='lightsalmon'),row=1, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,title_text='Yearly and Monthly Total New And Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [29]:
fig = make_subplots(rows=1, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Total Daily Vax.</b>',
                '<b>Cumulative Daily Vax.</b>',
                '<b>Full, Partial & Booster</b>',
                '<b>Pfizer, Sinovac, AZ & Cansino</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily'],name='Total Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Vax. (%)'],name='Vax. (%)',
                           line = dict(color='blue',width=0.5)),row=1, col=1,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Cum. Daily'],name='Cum. Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=2,secondary_y=False)
fig.add_hline(y=df_mas_vaksin['Cum. Daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Cum. Vax.", annotation_position="top left",row=1, col=2)
#Grpah 3
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_partial'],name='Partial',
                           line = dict(color='red',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_full'],name='Full',
                           line = dict(color='blue',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_booster'],name='Booster',
                           line = dict(color='green',width=0.5)),row=1, col=3,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Pfizer'],name='Pfizer',
                           line = dict(color='red',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Sinovac'],name='Sinovac',
                           line = dict(color='blue',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total AstraZ'],name='Astra Zaneca',
                           line = dict(color='green',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['cansino'],name='Cansino',
                           line = dict(color='black',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False,title_text="Daily Vaccination Details", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [30]:
df_mas_cases['total_vax'] = df_mas_cases['cases_pvax'] + df_mas_cases['cases_fvax']
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_cases['cum_vax'] = df_mas_cases['total_vax'].cumsum()
In [31]:
df_mas_deaths['total_vax'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax']
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new_dod'].cumsum()
df_mas_deaths['cum_vax'] = df_mas_deaths['total_vax'].cumsum()
In [32]:
fig = make_subplots(shared_xaxes=True, specs=[[{'secondary_y': True}]])

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'], name = 'Recovered Cases',
               line = dict(color='red', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['total_vax'], name = 'Vax. Cases',
               line = dict(color='green', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name ='Cumulative Cases', 
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'], name = 'Cumulative Recovered',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_vax'], name = 'Cumulative Vax.',
               line = dict(color='green', width=1)), secondary_y=False, row=1, col=1)

fig.update_layout(title_text='Malaysia Covid19 New And Recovered Cases', title_x=0.5, showlegend=False,
                 height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-10-11', x1='2021-10-11',  y0=0, y1=1000000)
fig.add_annotation(text='90% Vax.', x='2021-10-11', y=1000000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2020-09-26', x1='2020-09-26',  y0=0, y1=500000)
fig.add_annotation(text='PRN Sabah', x='2020-09-26', y=500000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-11-20', x1='2021-11-20',  y0=0, y1=500000)
fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=500000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-12-06', x1='2021-12-06',  y0=0, y1=400000)
fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=400000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-01-12', x1='2021-01-12',  y0=0, y1=600000)
fig.add_annotation(text='Darurat Mula', x='2021-01-12', y=600000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-08-01', x1='2021-08-01',  y0=0, y1=1100000)
fig.add_annotation(text='Darurat Tamat', x='2021-08-01', y=1100000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.show()
In [33]:
#Forecasting of New Cases VS Recovered Cases
#Importing the required module
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
from statsmodels.tsa.statespace.varmax import VARMAX
from statsmodels.tsa.api import VAR
#from statsmodels.tsa.stattools import grangercausalitytests, adfuller
from tqdm import tqdm_notebook
from itertools import product
import statsmodels.api as sm
import warnings
warnings.filterwarnings('ignore')
#Importing the required datasets
filepath_cases = 'https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv'
filepath_deaths = "https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv"
filepath_vaksin = 'https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv'
#Preparing the required datasets
filepath_cases = pd.read_csv(filepath_cases, parse_dates=['date'], index_col='date').astype('float64')
filepath_deaths = pd.read_csv(filepath_deaths, parse_dates=['date'], index_col='date').astype('float64')
filepath_vaksin = pd.read_csv(filepath_vaksin, parse_dates=['date'], index_col='date').astype('float64')
macro_data = pd.merge(filepath_cases,filepath_deaths,on='date')
macro_data = pd.merge(macro_data,filepath_vaksin,on='date')
macro_data['cases_vax_total'] = macro_data['cases_pvax'] + macro_data['cases_fvax']
macro_data['deaths_vax_total'] = macro_data['deaths_pvax'] + macro_data['deaths_fvax']
macro_data = macro_data[['cases_new','cases_vax_total']]
train_df=macro_data[:-12]
test_df=macro_data[-180:]
model = VAR(train_df.diff()[1:])
sorted_order=model.select_order(maxlags=30)
var_model = VARMAX(train_df, order=(4,0),enforce_stationarity= False)
fitted_model = var_model.fit(disp=True)
#Creating the required forecast
n_forecast = 180
predict = fitted_model.get_prediction(start=len(train_df),end=len(train_df) + n_forecast-1)
predictions=predict.predicted_mean
predictions.columns=['cases_predicted','cases_vax_total_predicted']
test_vs_pred=pd.concat([test_df,predictions],axis=1)
test_vs_pred = test_vs_pred.reset_index()
test_vs_pred['cases_new_cum'] = test_vs_pred['cases_new'].cumsum()
test_vs_pred['cases_vax_total_cum'] = test_vs_pred['cases_vax_total'].cumsum()
test_vs_pred['cases_predicted_cum'] = test_vs_pred['cases_predicted'].cumsum()
test_vs_pred['cases_vax_total_predicted_cum'] = test_vs_pred['cases_vax_total_predicted'].cumsum()
#Plotting the required forecast
fig = make_subplots(specs=[[{'secondary_y': True}]])
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=True)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new_cum'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=False)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_vax_total'], name = 'Positive Cases After Vaccinated',
               line = dict(color='red', width=1)), secondary_y=True)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_vax_total_cum'], name = 'Positive Cases After Vaccinated',
               line = dict(color='red', width=1)), secondary_y=False)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_predicted'], name = 'Predicted Positive Cases',
              line = dict(color='blue', width=0.75)), secondary_y=True)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_vax_total_predicted'], name = 'Predicted Positive Cases After Vaccinated',
              line = dict(color='red', width=0.75)), secondary_y=True)


fig.update_layout(title_text='Malaysia Covid19 Forecast of Positive & Active Cases (Based on VAR Model)', 
                  title_x=0.5,showlegend=False, height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-10-11', x1='2021-10-11',  y0=0, y1=800000)
fig.add_annotation(text='90% Adult Vax.', x='2021-10-11', y=800000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-11-20', x1='2021-11-20',  y0=0, y1=600000)
fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=600000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-12-06', x1='2021-12-06',  y0=0, y1=500000)
fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=500000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.show()
In [34]:
df = df_states_cases
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Cases & Recovered At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [35]:
df = df_states_deaths
df['deaths_vax_total'] = df['deaths_fvax'] + df['deaths_pvax'] 
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Deaths Total & Vaccinated At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [36]:
#Extracting And Separating Data For Each States
#Johor
df = df_states_vaksin
df_joh = df[df.state == 'Johor']
df_joh['cum_partial'] = df_joh['daily_partial'].cumsum()
df_joh['cum_full'] = df_joh['daily_full'].cumsum()
df_joh['cum_booster'] = df_joh['daily_booster'].cumsum()
#Kedah
df_ked = df[df.state == 'Kedah']
df_ked['cum_partial'] = df_ked['daily_partial'].cumsum()
df_ked['cum_full'] = df_ked['daily_full'].cumsum()
df_ked['cum_booster'] = df_ked['daily_booster'].cumsum()
#Kelantan
df_kel = df[df.state == 'Kelantan']
df_kel['cum_partial'] = df_kel['daily_partial'].cumsum()
df_kel['cum_full'] = df_kel['daily_full'].cumsum()
df_kel['cum_booster'] = df_kel['daily_booster'].cumsum()
#Melaka
df_mel = df[df.state == 'Melaka']
df_mel['cum_partial'] = df_mel['daily_partial'].cumsum()
df_mel['cum_full'] = df_mel['daily_full'].cumsum()
df_mel['cum_booster'] = df_mel['daily_booster'].cumsum()
#Negeri Sembilan
df_neg = df[df.state == 'Negeri Sembilan']
df_neg['cum_partial'] = df_neg['daily_partial'].cumsum()
df_neg['cum_full'] = df_neg['daily_full'].cumsum()
df_neg['cum_booster'] = df_neg['daily_booster'].cumsum()
#Pahang
df_pah = df[df.state == 'Pahang']
df_pah['cum_partial'] = df_pah['daily_partial'].cumsum()
df_pah['cum_full'] = df_pah['daily_full'].cumsum()
df_pah['cum_booster'] = df_pah['daily_booster'].cumsum()
#Perak
df_prk = df[df.state == 'Perak']
df_prk['cum_partial'] = df_prk['daily_partial'].cumsum()
df_prk['cum_full'] = df_prk['daily_full'].cumsum()
df_prk['cum_booster'] = df_prk['daily_booster'].cumsum()
#Perlis
df_per = df[df.state == 'Perlis']
df_per['cum_partial'] = df_per['daily_partial'].cumsum()
df_per['cum_full'] = df_per['daily_full'].cumsum()
df_per['cum_booster'] = df_per['daily_booster'].cumsum()
#Pulau Pinang
df_pen = df[df.state == 'Pulau Pinang']
df_pen['cum_partial'] = df_pen['daily_partial'].cumsum()
df_pen['cum_full'] = df_pen['daily_full'].cumsum()
df_pen['cum_booster'] = df_pen['daily_booster'].cumsum()
#Sabah
df_sab = df[df.state == 'Sabah']
df_sab['cum_partial'] = df_sab['daily_partial'].cumsum()
df_sab['cum_full'] = df_sab['daily_full'].cumsum()
df_sab['cum_booster'] = df_sab['daily_booster'].cumsum()
#Sarawak
df_sar = df[df.state == 'Sarawak']
df_sar['cum_partial'] = df_sar['daily_partial'].cumsum()
df_sar['cum_full'] = df_sar['daily_full'].cumsum()
df_sar['cum_booster'] = df_sar['daily_booster'].cumsum()
#Selangor
df_sel = df[df.state == 'Selangor']
df_sel['cum_partial'] = df_sel['daily_partial'].cumsum()
df_sel['cum_full'] = df_sel['daily_full'].cumsum()
df_sel['cum_booster'] = df_sel['daily_booster'].cumsum()
#Terengganu
df_ter = df[df.state == 'Terengganu']
df_ter['cum_partial'] = df_ter['daily_partial'].cumsum()
df_ter['cum_full'] = df_ter['daily_full'].cumsum()
df_ter['cum_booster'] = df_ter['daily_booster'].cumsum()
#Kuala Lumpur
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_kul['cum_partial'] = df_kul['daily_partial'].cumsum()
df_kul['cum_full'] = df_kul['daily_full'].cumsum()
df_kul['cum_booster'] = df_kul['daily_booster'].cumsum()
#Labuan
df_lab = df[df.state == 'W.P. Labuan']
df_lab['cum_partial'] = df_lab['daily_partial'].cumsum()
df_lab['cum_full'] = df_lab['daily_full'].cumsum()
df_lab['cum_booster'] = df_lab['daily_booster'].cumsum()
#Putrajaya
df_put = df[df.state == 'W.P. Putrajaya']
df_put['cum_partial'] = df_put['daily_partial'].cumsum()
df_put['cum_full'] = df_put['daily_full'].cumsum()
df_put['cum_booster'] = df_put['daily_booster'].cumsum()
In [37]:
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Vaccination (1D, 2D & 3D) At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [38]:
dfpop = df_states_pop
#Creating new vax percentage columns at each states
#Johor
df_joh_pop = dfpop[dfpop.state == 'Johor']
df_joh_pop = df_joh_pop.at[df_joh_pop.index[0],'pop']
df_joh['2 Dos (%)'] = (df_joh['cum_full']/df_joh_pop)*100
#Kedah
df_ked_pop = dfpop[dfpop.state == 'Kedah']
df_ked_pop = df_ked_pop.at[df_ked_pop.index[0],'pop']
df_ked['2 Dos (%)'] = (df_ked['cum_full']/df_ked_pop)*100
#Kelantan
df_kel_pop = dfpop[dfpop.state == 'Kelantan']
df_kel_pop = df_kel_pop.at[df_kel_pop.index[0],'pop']
df_kel['2 Dos (%)'] = (df_kel['cum_full']/df_kel_pop)*100
#Melaka
df_mel_pop = dfpop[dfpop.state == 'Melaka']
df_mel_pop = df_mel_pop.at[df_mel_pop.index[0],'pop']
df_mel['2 Dos (%)'] = (df_mel['cum_full']/df_mel_pop)*100
#Negeri Sembilan
df_neg_pop = dfpop[dfpop.state == 'Negeri Sembilan']
df_neg_pop = df_neg_pop.at[df_neg_pop.index[0],'pop']
df_neg['2 Dos (%)'] = (df_neg['cum_full']/df_neg_pop)*100
#Pahang
df_pah_pop = dfpop[dfpop.state == 'Pahang']
df_pah_pop = df_pah_pop.at[df_pah_pop.index[0],'pop']
df_pah['2 Dos (%)'] = (df_pah['cum_full']/df_pah_pop)*100
#Perak
df_prk_pop = dfpop[dfpop.state == 'Perak']
df_prk_pop = df_prk_pop.at[df_prk_pop.index[0],'pop']
df_prk['2 Dos (%)'] = (df_prk['cum_full']/df_prk_pop)*100
#Perlis
df_per_pop = dfpop[dfpop.state == 'Perlis']
df_per_pop = df_per_pop.at[df_per_pop.index[0],'pop']
df_per['2 Dos (%)'] = (df_per['cum_full']/df_per_pop)*100
#Penang
df_pen_pop = dfpop[dfpop.state == 'Pulau Pinang']
df_pen_pop = df_pen_pop.at[df_pen_pop.index[0],'pop']
df_pen['2 Dos (%)'] = (df_pen['cum_full']/df_pen_pop)*100
#Sabah
df_sab_pop = dfpop[dfpop.state == 'Sabah']
df_sab_pop = df_sab_pop.at[df_sab_pop.index[0],'pop']
df_sab['2 Dos (%)'] = (df_sab['cum_full']/df_sab_pop)*100
#Sarawak
df_sar_pop = dfpop[dfpop.state == 'Sarawak']
df_sar_pop = df_sar_pop.at[df_sar_pop.index[0],'pop']
df_sar['2 Dos (%)'] = (df_sar['cum_full']/df_sar_pop)*100
#Selangor
df_sel_pop = dfpop[dfpop.state == 'Selangor']
df_sel_pop = df_sel_pop.at[df_sel_pop.index[0],'pop']
df_sel['2 Dos (%)'] = (df_sel['cum_full']/df_sel_pop)*100
#Terengganu
df_ter_pop = dfpop[dfpop.state == 'Terengganu']
df_ter_pop = df_ter_pop.at[df_ter_pop.index[0],'pop']
df_ter['2 Dos (%)'] = (df_ter['cum_full']/df_ter_pop)*100
#Kuala Lumpur
df_kul_pop = dfpop[dfpop.state == 'W.P. Kuala Lumpur']
df_kul_pop = df_kul_pop.at[df_kul_pop.index[0],'pop']
df_kul['2 Dos (%)'] = (df_kul['cum_full']/df_kul_pop)*100
#Labuan
df_lab_pop = dfpop[dfpop.state == 'W.P. Labuan']
df_lab_pop = df_lab_pop.at[df_lab_pop.index[0],'pop']
df_lab['2 Dos (%)'] = (df_lab['cum_full']/df_lab_pop)*100
#Putrajaya
df_put_pop = dfpop[dfpop.state == 'W.P. Putrajaya']
df_put_pop = df_put_pop.at[df_put_pop.index[0],'pop']
df_put['2 Dos (%)'] = (df_put['cum_full']/df_put_pop)*100
#Start creating the graph
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=2)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=4)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=1)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=2)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=3)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=4)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=1)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=2)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=3)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=4)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=1)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=2)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=3)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=4)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,
                  title_text="Covid19 Vaccination Against Vaccination Per Population At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [39]:
#Retrieving dataset for Covid19 for all countries
dfworld = pd.read_csv('https://raw.githubusercontent.com/datasets/covid-19/main/data/time-series-19-covid-combined.csv')
dfworld['daily_cases'] = dfworld['Confirmed'].diff()
dfworld['daily_recover'] = dfworld['Recovered'].diff()
dfworld['daily_deaths'] = dfworld['Deaths'].diff()
In [40]:
dfworld2 = pd.read_csv('https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/latest/owid-covid-latest.csv')
dfworld2 = dfworld2[dfworld2['continent'].notna()] 
dfworld2 = dfworld2[['location','total_cases','total_deaths','people_vaccinated',
                     'population','population_density','gdp_per_capita']]
dfworld2['Cases (%)'] = (dfworld2['total_cases']/dfworld2['population'])*100
dfworld2['Deaths (%)'] = (dfworld2['total_deaths']/dfworld2['total_cases'])*100
dfworld2['Vaccination (%)'] = (dfworld2['people_vaccinated']/dfworld2['population'])*100

dfworld2.rename(columns={'location':'Country','total_cases':'Total Cases','total_deaths':'Total Deaths',
                         'people_vaccinated':'People Vaccinated','population':'Population',
                         'population_density':'Population Density','gdp_per_capita':'GDP Per Kapita'},inplace=True)
In [41]:
df_asean = dfworld2.loc[dfworld2['Country'].isin(['Malaysia','Singapore','Thailand','Indonesia',
                                              'Philippines','Cambodia','Laos','Vietnam',
                                              'Myanmar','Brunei'])]
df_asean = df_asean.sort_values('Total Cases',ascending=False)
def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

df_asean.style.set_caption("Overview Of Covid19 Cases In ASEAN Countries").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[41]:
Overview Of Covid19 Cases In ASEAN Countries
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
Indonesia 4,301,193 144,254 182,500,827 276,361,788 145.7 11,188.7 1.6 3.4 66.0
Philippines 3,475,293 53,664 nan 111,046,910 351.9 7,599.2 3.1 1.5 nan
Malaysia 2,844,969 31,930 26,063,871 32,776,195 96.3 26,808.2 8.7 1.1 79.5
Thailand 2,407,022 22,098 51,922,910 69,950,844 135.1 16,277.7 3.4 0.9 74.2
Vietnam 2,187,481 37,165 78,894,694 98,168,829 308.1 6,171.9 2.2 1.7 80.4
Myanmar 534,503 19,310 21,361,785 54,806,014 81.7 5,591.6 1.0 3.6 39.0
Singapore 327,602 850 4,907,259 5,453,600 7,915.7 85,535.4 6.0 0.3 90.0
Laos 131,432 533 4,653,477 7,379,358 29.7 6,397.4 1.8 0.4 63.1
Cambodia 121,116 3,015 14,345,304 16,946,446 90.7 3,645.1 0.7 2.5 84.7
Brunei 16,179 98 406,768 441,532 81.3 71,809.3 3.7 0.6 92.1
In [42]:
#Selecting datasets for ASEAN Countries
#Malaysia
dfworld.rename(columns={'Country/Region':'Country'},inplace=True)
df_mas = dfworld[dfworld.Country == 'Malaysia']
df_mas = df_mas.reset_index(drop=True)
df_mas = df_mas.drop([0])
#Indonesia
df_ind = dfworld[dfworld.Country == 'Indonesia']
df_ind = df_ind.reset_index(drop=True)
df_ind = df_ind.drop([0])
#Philippines
df_phi = dfworld[dfworld.Country == 'Philippines']
df_phi = df_phi.reset_index(drop=True)
df_phi = df_phi.drop([0])
#Burma
df_bur = dfworld[dfworld.Country == 'Burma']
df_bur = df_bur.reset_index(drop=True)
df_bur = df_bur.drop([0])
#Singapore
df_sin = dfworld[dfworld.Country == 'Singapore']
df_sin = df_sin.reset_index(drop=True)
df_sin = df_sin.drop([0])
#Thailand
df_tha = dfworld[dfworld.Country == 'Thailand']
df_tha = df_tha.reset_index(drop=True)
df_tha = df_tha.drop([0])
#Vietnam
df_vie = dfworld[dfworld.Country == 'Vietnam']
df_vie = df_vie.reset_index(drop=True)
df_vie = df_vie.drop([0])
#Cambodia
df_cam = dfworld[dfworld.Country == 'Cambodia']
df_cam = df_cam.reset_index(drop=True)
df_cam = df_cam.drop([0])
#Brunei
df_bru = dfworld[dfworld.Country == 'Brunei']
df_bru = df_bru.reset_index(drop=True)
df_bru = df_bru.drop([0])
#Laos
df_lao = dfworld[dfworld.Country == 'Laos']
df_lao = df_lao.reset_index(drop=True)
df_lao = df_lao.drop([0])
In [43]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [44]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total Deaths And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [45]:
dfworld3 = dfworld2.sort_values('Total Cases',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 Cases Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[45]:
Overview Of Top 10 Highest Covid19 Cases Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
United States 72,910,136 876,065 251,518,114 332,915,074 35.6 54,225.4 21.9 1.2 75.6
India 40,371,500 491,700 934,468,791 1,393,409,033 450.4 6,426.7 2.9 1.2 67.1
Brazil 24,560,093 624,717 168,921,071 213,993,441 25.0 14,103.5 11.5 2.5 78.9
France 17,782,057 129,813 53,670,900 67,422,000 122.6 38,605.7 26.4 0.7 79.6
United Kingdom 16,189,420 154,831 52,265,883 68,207,114 272.9 39,753.2 23.7 1.0 76.6
Turkey 11,167,927 86,487 57,371,915 85,042,736 104.9 25,129.3 13.1 0.8 67.5
Russia 11,129,318 321,484 76,024,218 145,912,022 8.8 24,766.0 7.6 2.9 52.1
Italy 10,383,561 144,770 49,923,700 60,367,471 205.9 35,220.1 17.2 1.4 82.7
Spain 9,529,320 92,591 40,848,444 46,745,211 93.1 34,272.4 20.4 1.0 87.4
Germany 9,317,280 117,318 62,838,649 83,900,471 237.0 45,229.2 11.1 1.3 74.9
In [46]:
dfworld3 = dfworld2.sort_values('People Vaccinated',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[46]:
Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 105,811 4,636 1,265,034,000 1,444,216,102 147.7 15,308.7 0.0 4.4 87.6
India 40,371,500 491,700 934,468,791 1,393,409,033 450.4 6,426.7 2.9 1.2 67.1
United States 72,910,136 876,065 251,518,114 332,915,074 35.6 54,225.4 21.9 1.2 75.6
Indonesia 4,301,193 144,254 182,500,827 276,361,788 145.7 11,188.7 1.6 3.4 66.0
Brazil 24,560,093 624,717 168,921,071 213,993,441 25.0 14,103.5 11.5 2.5 78.9
Pakistan 1,393,887 29,162 103,805,835 225,199,929 255.6 5,034.7 0.6 2.1 46.1
Japan 2,354,358 18,601 101,379,174 126,050,796 347.8 39,002.2 1.9 0.8 80.4
Bangladesh 1,731,524 28,273 95,440,321 166,303,494 1,265.0 3,524.0 1.0 1.6 57.4
Mexico 4,730,669 303,776 83,386,735 130,262,220 66.4 17,336.5 3.6 6.4 64.0
Vietnam 2,187,481 37,165 78,894,694 98,168,829 308.1 6,171.9 2.2 1.7 80.4
In [47]:
dfworld3 = dfworld2.sort_values('Population',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Population Countries Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[47]:
Overview Of Top 10 Highest Population Countries Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 105,811 4,636 1,265,034,000 1,444,216,102 147.7 15,308.7 0.0 4.4 87.6
India 40,371,500 491,700 934,468,791 1,393,409,033 450.4 6,426.7 2.9 1.2 67.1
United States 72,910,136 876,065 251,518,114 332,915,074 35.6 54,225.4 21.9 1.2 75.6
Indonesia 4,301,193 144,254 182,500,827 276,361,788 145.7 11,188.7 1.6 3.4 66.0
Pakistan 1,393,887 29,162 103,805,835 225,199,929 255.6 5,034.7 0.6 2.1 46.1
Brazil 24,560,093 624,717 168,921,071 213,993,441 25.0 14,103.5 11.5 2.5 78.9
Nigeria 252,753 3,134 13,772,458 211,400,704 209.6 5,338.5 0.1 1.2 6.5
Bangladesh 1,731,524 28,273 95,440,321 166,303,494 1,265.0 3,524.0 1.0 1.6 57.4
Russia 11,129,318 321,484 76,024,218 145,912,022 8.8 24,766.0 7.6 2.9 52.1
Mexico 4,730,669 303,776 83,386,735 130,262,220 66.4 17,336.5 3.6 6.4 64.0

End Of Report